package com.sky.config;

import org.springframework.amqp.core.*;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration
public class mqConfiguration {
    //订单交换机
    @Bean
    public DirectExchange orderExchange(){
        return new DirectExchange("order.exchange",true,false);
    }
    //死信交换机
    @Bean
    public DirectExchange dlExchange(){
        return new DirectExchange("dl.exchange",true,false);
    }

    @Bean
    public Queue dlQueue(){
        return new Queue("dl.queue",true);
    }


    //支付成功队列
    @Bean
    public Queue successQueue(){
        return QueueBuilder.durable("success.queue")
                .deadLetterExchange("dl.exchange")
                .deadLetterRoutingKey("dl")
                .ttl(60000)
                .build();
    }

    @Bean
    public Binding dlBinding(){
        return BindingBuilder.bind(dlQueue()).to(dlExchange()).with("dl");
    }

    @Bean
    public Binding orderBinding(){
        return BindingBuilder.bind(successQueue()).to(orderExchange()).with("success");
    }
}
